package com.xcdh.orm.util;

import com.xcdh.commons.utils.DataSourceContextHolder;

import java.util.function.Supplier;

/**
 * DatabaseSwitchUtil
 *
 * @author wjg
 * @date 2023/12/21
 */
public class DatabaseSwitchUtil {

    public static <T> T changeService(String serviceId , Supplier<T> fun){
        try{
            DataSourceContextHolder.set(serviceId);
            return fun.get() ;
        }finally {
            DataSourceContextHolder.clear();
        }
    }


}
